package com.zhiyou100.blog.aciton.title;

import com.zhiyou100.blog.entity.Title;
import com.zhiyou100.blog.service.TitleService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * @author shkstart
 * @create 2021-10-23 21:09
 */
@WebServlet("/title/add")
public class TitleAddServlet extends HttpServlet {
    private TitleService service = new TitleService();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String uid = request.getParameter("uid");
        String tname = request.getParameter("tname");
        String tcontent = request.getParameter("tcontent");
        Title title = new Title(tname, tcontent, new Date(), 0, Integer.parseInt(uid));
        System.out.println("title = " + title);
        service.appentTitle(title);
        request.getRequestDispatcher("/title/paging").forward(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
